<!--
 * @Author: GKN
 * @Date: 2023-10-24 11:53:29
 * @LastEditTime: 2024-01-02 11:03:08
 * @LastEditors: GKN
 * @Description: 
 * @FilePath: \mod\src\view\user\create\a1.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->
<template>
    <div v-loading="loading">
        <el-form :model="form" label-width="120px" size="large">
            <el-form-item label="标题">
                <el-col :span="12">
                    <el-input v-model="form.name"/>
                </el-col>
            </el-form-item>
            <el-form-item label="作者">
                <el-col :span="12">
                    <el-input v-model="form.creator"/>
                </el-col>
            </el-form-item>
            <el-form-item label="正文">
                <el-col :span="12">
                    <el-upload
                        v-model:file-list="fileList"
                        ref="uploadfile"
                        class="avatar-uploader"
                        :action="fileUrl"
                        :auto-upload="false"
                        @change="handleUploadChange"
                    >
                    <div class="uploadCard">
                        <!-- <img v-if="imageUrl" :src="imageUrl" class="avatar" /> -->
                        <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
                    </div>
                    <div class="flex" style="align-items: flex-end;height: 106px;margin-left: 10px;">
                        <span style="font-size: 14px;color: #8D8D8D;">需上传word格式文档</span>
                    </div>
                    </el-upload>
                    
                </el-col>
            </el-form-item>
            <el-form-item label="内容简介">
                <el-col :span="12">
                    <el-input type="textarea" placeholder="填写内容简介" maxlength="1000" :rows="10" show-word-limit v-model="form.blurb"/>
                </el-col>
            </el-form-item>
            <el-form-item label="文物分类">
                <el-col :span="12">
                    <el-radio-group v-model="form.vot">
                        <el-radio :label="2" >成果类</el-radio>
                        <el-radio :label="1" >论文类</el-radio>
                    </el-radio-group>
                </el-col>
            </el-form-item>
            <el-form-item label="主题方向">

                <div class="fl flex flex-w" style="width: 100%;">
                    <div style="width:50%;margin-bottom:10px;" class="flex flex-w" v-for="(items,is) in list_fl1" :key="is">
                        <div class="flex flex-w flex-align flex-j-c ztB-red" style="">{{ items.name }}</div>
                        <div class="flex flex-w" style="padding-left:10px;width: 80%;">
                            <div v-for="(item,i) in items.theme" :key="i" :class="item.select?'omit active flview MarB-5':'omit flview MarB-5'" @click="click_fl1(is,i,item.select)">
                                {{item.name}}
                                <span style="margin-left:5px;">|</span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
            </el-form-item>
            <el-form-item label="行业分类">
                <div class="fl flex flex-w" style="width: 100%;">
                    <div v-for="(item,i) in list_fl2" :key="i" :class="item.select?'active flview MarB-5':'flview MarB-5'" @click="click_fl2(i,item.select)">
                        {{item.name}}
                        <span style="margin-left:5px;">|</span>
                    </div>
                </div>
                
            </el-form-item>
            <el-form-item label="区域分类">
                <div class="fl flex flex-w" style="width: 100%;">
                    <div v-for="(item,i) in list_fl3" :key="i" :class="item.select?'active flview MarB-5':'flview MarB-5'" @click="click_fl3(i,item.select)">
                        {{item.name}}
                        <span style="margin-left:5px;">|</span>
                    </div>
                </div>
                
            </el-form-item>
            <el-form-item label="行业细分">
                <el-col :span="12">
                    <el-input v-model="form.sName" placeholder="50字以内"/>
                </el-col>
            </el-form-item>
            <!-- <el-form-item label="其他关键词">
                <el-col :span="12">
                    <el-input v-model="form.sName" placeholder="50字以内"/>
                </el-col>
            </el-form-item> -->
        </el-form>
        <div class="btn-submit cursor-p" @click="submit" style="">提交</div>
        <el-dialog v-model="is_yc" title="" width="30%" style="border-radius:15px;">
            <div style="font-size:24px;font-weight:bold;color:#333;">原创声明</div>
            <div style="padding-top:66px;">
                <div class="btn-submit cursor-p" @click="submit_s" >确认原创</div>
                <div style="margin-top:20px;">阅读并提交<span style="color: #d00b00;;">原创声明</span></div>
            </div>
        </el-dialog>
    </div>
    
</template>

<script setup>
import { ref,reactive,getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
import { Plus } from '@element-plus/icons-vue'
import * as qiniu from 'qiniu-js'
import md5 from 'js-md5'
    const is_yc= ref(false)
    const form = ref({ ft:1})
    const loading = ref(false)
    // 主题方向
    const list_fl1 = ref([])
    const theme_list = ref([])
    const getTheme=()=>{
        proxy.$http.request(proxy.$api.theme,'get',{},false, function (res) {
            if(res&&res.data){
                list_fl1.value = []
                res.data.data.list.map((item)=>{
                    list_fl1.value.push({
                        ...item,
                        select:false
                    })
                })
            }
        })
    }
    getTheme()
    const searchselect=(arr)=>{
        var newArr = []
        arr.map((item)=>{
            if(item.select){
                newArr.push(item.id)
            }
        })
        return newArr;
    }
    const setTheme=()=>{
        theme_list.value =[]
        list_fl1.value.map((item)=>{
            if(item.theme!= null&&searchselect(item.theme).length>0){
                searchselect(item.theme).map((item)=>{
                    theme_list.value.push(item.toString())
                })
                
            }
        })
    }
    const click_fl1 = (i1,i2,t)=>{
        list_fl1.value[i1].theme[i2].select = !t
        setTheme()
    }
    // 区域列表
    const list_fl3 = ref([])
    const getArea=()=>{
        proxy.$http.request(proxy.$api.area,'get',{},false, function (res) {
            if(res&&res.data){
                list_fl3.value = []
                res.data.data.list.map((item)=>{
                    list_fl3.value.push({
                        ...item,
                        select:false
                    })
                })
            }
        })
    }
    getArea()
    const click_fl3 = (i,t)=>{
        list_fl3.value.map((item)=>{
            item.select = false
        })
        list_fl3.value[i].select = true
        form.value.areaId = list_fl3.value[i].aid
    }
    // 分类列表
    const list_fl2 = ref([])
    const getClass=()=>{
        proxy.$http.request(proxy.$api.classlist+'?ty=1','get',{},false, function (res) {
            if(res&&res.data){
                list_fl2.value = []
                res.data.data.list.map((item)=>{
                    list_fl2.value.push({
                        ...item,
                        select:false
                    })
                })
            }
        })
    }
    getClass()
    const click_fl2 = (i,t)=>{
        list_fl2.value.map((item)=>{
            item.select = false
        })
        list_fl2.value[i].select = true
        form.value.cateId = list_fl2.value[i].id
    }
    const progress = ref('')
    // 服务器资源
    const fileUrl = ref('')
    const qnToken = ref('')
    const get_resource =()=>{
        proxy.$http.request(proxy.$api.get_resource,'get',{},false, function (res) {
            if(res&&res.data){
                fileUrl.value = res.data.data.fileUrl
            }
        })
    }
    get_resource()
    const headers = ref({
        Authorization: ''
    })
    const get_qntoken =()=>{
        proxy.$http.request(proxy.$api.qnToken+'3','get',{},false, function (res) {
            if(res&&res.data){
                qnToken.value = res.data.data.token
                headers.value.Authorization = res.data.data.token
            }
        })
    }
    get_qntoken()
    // 头像上传
    const uploadfile = ref(null)
    const fileList = ref([])
    // 必须手动上传文件
    const handleUploadChange = (event) => {
        const file = event.raw;
        var key =  Math.random().toString(36).substring(2)+"_"+ file.name
        const observable = qiniu.upload(file, key, qnToken.value,{fname:key})
        const observer = {
            next(res) {
                progress.value = res.total.percent
            },
            error(res) {
                
            },
            complete(res) {
                //执行上传成功后的逻辑
                form.value.file = res.key
            }
        }
        observable.subscribe(observer);
    };
    const submit = ()=>{
        const data = form.value
        if(!data.file){
            proxy.$comJs.msg('error','请上传文件')
            return;
        }
        if(!data.name){
            proxy.$comJs.msg('error','请填写文章名')
            return;
        }
        if(!data.blurb){
            proxy.$comJs.msg('error','请填写内容简介')
            return;
        }
        if(!data.vot){
            proxy.$comJs.msg('error','请选择分类')
            return;
        }
        is_yc.value = true
        // loading.value = true
        // setTimeout(()=>{
        //     loading.value = false
        // },300)
        
    }
    const submit_s=()=>{
        const data = {
            ...form.value,
            "themeId":theme_list.value
        }
        proxy.$http.request(proxy.$api.upload_doc,'post',data,false, function (res) {
            if(res&&res.data){
                if(res.data.code == 0){
                    proxy.$comJs.msg('success','提交成功')   
                }
                is_yc.value = false
                
            }
        })
    }
</script>

<style lang='less' scoped>
/deep/ .el-input--large .el-input__wrapper{
    padding: 0 0px;
    background:#f6f7f9;
    
}
/deep/ .el-textarea__inner{
    background:#f6f7f9;
    padding: 10px 10px;
}
/deep/.el-input--large .el-input__inner{
    padding:0 10px;
}
::v-deep {

.el-input__inner {
  border: 0;
  border-radius: 0px;

  // &:focus {
  //   border-bottom: 1px solid #409eff;
  // }
}

.el-textarea__inner {
  resize: none;
  /* 这个是去掉 textarea 下面拉伸的那个标志，如下图 */
  border: 0;
  border-radius: 0px;

  // &:focus {
  //   border-bottom: 1px solid #409eff;
  // }
}
}
.avatar-uploader{
    display: flex;
    align-items: flex-end;
    
}
.avatar-uploader .avatar {
  width: 106px;
  height: 106px;
  display: block;
}
.fl{

    .active{
        color: #CF0B00;
    }
    .flview{
        font-size: 14px;
        font-weight: 400;
        cursor: pointer;
        margin-right: 5px;
        line-height: 18px;
    }
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
  background:#f6f7f9;
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 106px;
  height: 106px;
  text-align: center;
}

.uploadCard{
    background: #f6f7f9;
}
</style>
  
  

